/*
** Copyright (C) 2009 Joshua Brent Marsh <joshua@icub3d.com>
**  
** This file is part of icub3d-adt.
**
** icub3d-adt is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 3 of the License, or
** (at your option) any later version.
**  
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**  
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**  
*/

/* $Id: logger.h 46 2009-11-17 03:57:00Z joshua@icub3d.com $ */

#ifndef ICUB3D_LOGGER_H
#define ICUB3D_LOGGER_H 1

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <stdarg.h>
#include <stdlib.h>
#include <syslog.h>
#include <string.h>
#include <unistd.h>

/* Basic logging. */
void logger_init (const char *ident, int option, int facility);
void logger_log(int priority, const char *format, ...);
void logger_vlog(int priority, const char *format, va_list args);
void logger_close ();

/* Some defines to help with the functions below. */
#define logger_stringify(x) #x
#define logger_tostring(x) logger_stringify(x)
#define logger_at __FILE__ ":" logger_tostring(__LINE__)

/* Debug logging. */
#define logger_dlog(priority, format, ...)			\
  logger_log (priority, "[-] [%s] [%s] " format, logger_at,	\
	      __FUNCTION__, ##__VA_ARGS__)

/* Function logging. */
#define logger_flog(priority, format, ...)				\
  logger_log (priority, "[-] [-] [%s] " format, __FUNCTION__,		\
	      ##__VA_ARGS__)


/* Debug logging with ID. */
#define logger_idlog(id, priority, format, ...)				\
  logger_log (priority, "[%zu] [%s] [%s] " format, id, logger_at,	\
	      __FUNCTION__, ##__VA_ARGS__)

/* Function logging with id. */
#define logger_iflog(id, priority, format, ...)				\
  logger_log (priority, "[%zu] [-] [%s] " format, id, __FUNCTION__,	\
	      ##__VA_ARGS__)

#endif /* ICUB3D_LOGGER_H */
